<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text" id='inp'>
    <h4 id='ceshi'></h4>
</body>
<script>
    var getId = function (id) {
        return document.getElementById(id)
    }
    var x = {
        _t: '测试',
        get fun() {  //get语法将对象属性绑定到一个匿名函数上，当获取的时候会执行这个函数
            return this._t
        },
        set fun(t) {
            getId('inp').value = t
            getId('ceshi').innerHTML = t
        }
    }

    getId('inp').addEventListener('keyup', (e) => {
        x.fun = e.target.value
    })


</script>

</html>